//
//  AirConditionerView.m
//  Test
//
//  Created by jingyao on 2017/12/21.
//  Copyright © 2017年 jingyao. All rights reserved.
//

#import "AirConditionerView.h"
#import "Global.h"

@interface AirConditionerView ()<UIPickerViewDelegate, UIPickerViewDataSource>

@property (nonatomic, strong) NSMutableArray *datasArray;

@end

//所有UIview的写法以这个页面为准
@implementation AirConditionerView

//采用。页面实际创建与xib或者storyboard有关的情况下使用，可替代initwithcoder方法，省去了判断self为不为空的麻烦
- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.datasArray = [[NSMutableArray alloc]initWithObjects:@"Warm", @"Slightly Warm", @"Comfort", @"Cool", @"Slightly Cool", nil];
    
    self.feellingPickerView.delegate = self;
    self.feellingPickerView.dataSource = self;
}
/*
//页面实际创建与xib或者storyboard有关的情况下使用
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        
    }
    return self;
}

//页面实际创建与xib，storyboard无关，纯代码创建时
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}

//绘图，uigraphics相关的代码用到的时候写在这里面
- (void)drawRect:(CGRect)rect {
    
}
*/
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return 5;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *title = nil;
    title = self.datasArray[row];
    return title;
}
- (IBAction)voteAction:(id)sender {
    [Global showTextOnly:@"Voted"];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UILabel *pickerLbl = (UILabel *)view;
    if (!pickerLbl) {
        pickerLbl = [[UILabel alloc] init];
        [pickerLbl setFont:[UIFont boldSystemFontOfSize:15]];
        [pickerLbl setBackgroundColor:[UIColor clearColor]];
        if ([pickerView selectedRowInComponent:0] == row) {
            pickerLbl.textColor = [UIColor colorWithRed:2/255.0f green:167/255.0f blue:146/255.0f alpha:1.0f];
        }else {
            pickerLbl.textColor = [UIColor lightGrayColor];
        }
    }
    pickerLbl.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    pickerLbl.textAlignment = NSTextAlignmentCenter;
    return pickerLbl;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    [self.feellingPickerView reloadAllComponents];
}
@end
